<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Response;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


    public function success($data = [], $message = '成功')
    {
        return $this->apiReturn(true, 200, $message, $data);
    }

    public function failure($message = '失败', $data = [], $code = 500)
    {
        return $this->apiReturn(false, $code, $message, $data);
    }

    public function apiReturn($status = true, $code = 200, $message = '成功', $data = [])
    {
        $box['status'] = $status;
        $box['code'] = $code;
        $box['message'] = $message;
        $box['data'] = $data;

        return Response::json($box);
    }
}
